var qrCommon = {
		showError : function(message, duration){
		    var toast = $('#toast');
		    clearTimeout(toast.timer);
		    if (message && message !== 'hide') {
		        toast.find('span').html(message);
		    } else if (message && message == 'hide') {
		        toast.hide();
		        return;
		    }
		    toast.show();
		    toast.timer = setTimeout(function () {
		        toast.hide();
		    }, duration || 2000);
		},
		// 获取URL参数
	    getUrlParams:function(t) {
			 var reg = new RegExp("(^|&)" + t + "=([^&]*)(&|$)");
		     var r = window.location.search.substr(1).match(reg);
		     if (r != null) return unescape(r[2]);
		     return null;
	    },
	  //姓名验证
	    _inputNameValidator: function (domVal) {
	    	this.showError("hide");
	        var nameVal = domVal;
	        if (!nameVal) {
	        	this.showError("请输入正确的姓名");
	            return false;
	        } else if (nameVal && !(/^([\u4e00-\u9fa5\s]{2}|[a-zA-Z]{4})([\u4e00-\u9fa5\s]{0,18}|[. ]{0,36}|[• ]{0,36}|[a-zA-Z]{0,36})?$/.test(nameVal))) {
	        	this.showError("请输入正确的姓名");
	            return false;
	        } else if (nameVal == '不详' || nameVal == '不祥' || nameVal == '未知' || nameVal == '不知道' || nameVal == '姓名' || nameVal.indexOf('测试') > -1 || nameVal.indexOf('test') > -1) {
	        	this.showError("请输入正确的姓名");
	            return false;
	        } else {
	        	this.showError("hide");
	            return true;
	        }
	        return true;
	    },
	    //手机号码验证
	    _inputTelValidator: function (domVal) {
	    	 var phoneVal = domVal;
	         if (!phoneVal) {
	        	 this.showError("请输入正确的手机号");
	             return false;
	         } else if (!/^(13|14|15|16|17|18|19)[0-9]{1}[0-9]{4}[0-9]{4}$/.test(phoneVal)) {
	        	 this.showError("请输入正确的手机号");
	             return false;
	         } else {
	             this.showError("hide");
	             return true;
	         }
	    },
		getCookie : function(cookieName) {
			var strCookie = document.cookie;
			var arrCookie = strCookie.split("; ");
			for(var i = 0; i < arrCookie.length; i++){
				var arr = arrCookie[i].split("=");
				if(cookieName == arr[0]){
					return arr[1];
				}
			}
			return "";
		},
		setCookie : function(name, value, path) {
			var d = new Date();
			d.setTime(d.getTime() + (30 * 60 * 1000));
			expires = d.toGMTString();

			value = escape(value);
			document.cookie = name + "=" + value + ";"
			+ (expires != -1 ? " expires=" + expires + ";" : "")
			+ (path ? "path=" + path : "");
		},
		clearTime: function () {
	        clearTimeout(window.toTimeoutPageId);
	        clearTimeout(window.flowIntervalId);
	    },

	    sessionTimeoutStart: function (flowid, notFirstTime, source) {
	        window.toTimeoutPageId = setTimeout(function () {//启动会话超时计时，并保存该计时ID,30分钟 30*60*1000=1800000
	            window.location.href = "qirong.html";
	        }, 1800000);
	        if (!notFirstTime) {
	            //启动保持流程计时器
	            qrCommon.keepFlow(flowid, source);
	            //用户点击了页面，清除两个之前的计时器，重新计时
	            $("body").bind("click", function () {
	                clearTimeout(toTimeoutPageId);
	                //clearTimeout(tipToUserTimeout);
	                qrCommon.sessionTimeoutStart(flowid, true);
	            });
	        }

	    },
	    /**
	     *    保持流程，每30秒发一次
	     */
	    keepFlow: function (flowid) {
	        if (flowid != '' && flowid != null) {
	            window.flowIntervalId = setInterval(function () {
	                $.ajax({
	                    url: "/do/keep-flow-ctx.do?flowId=" + flowid,
	                    dataType: "json",
	                    success: function (data) {
	                        if (data.resultCode != '0') {
	                            clearInterval(flowIntervalId);
	                        }
	                    },
	                    error: function () {
	                    	window.location.href = "qirong.html";
	                    }
	                });
	            }, 30000);
	        }
	    }
};


//百度可以统计按键量
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?5cc92e7a9a37a0546a5bf7d217afb282";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();

//pc版webtrends代码
function loadWTScript(a, b) {
	var c = document.createElement("script");
	c.type = "text/javascript",
	c.async = !0, c.id='wtjs',
	c.src = a,
	dcsReady(c, b),
	document.getElementsByTagName("head")[0].appendChild(c)
}
function dcsReady(a, b) {
	a.readyState ? a.onreadystatechange = function() { ("loaded" == a.readyState || "complete" == a.readyState) && (a.onreadystatechange = null, b())
	}: a.onload = function() {
		b()
	}
} 
if(document.getElementById("wtjs")==null)
loadWTScript(window.location.protocol.indexOf('https:')==0?'https://pa-ssl.pingan.com/app_js/sdc/prd/sdc9_m.js':'http://www.pingan.com/app_js/sdc/prd/sdc9_m.js', function(){ 
    if (typeof(_tag) != "undefined"){
      _tag.dcsid="dcs82b9ujitigdu3gaykxw0hn_5p6b";  //dcsid参数用于设置日志记录在哪个文件里
        _tag.DCSext.platform="xxxx";  //平台名字
        var s=_tag.dcsGetIdAsync();
        if(s) 
            dcsReady(s,function(){_tag.dcsCollect()});
        else
            _tag.dcsCollect();
    }
})
